package com.example.mytayunapi.Service;

import com.example.mytayunapi.Entity.ProductImagesInfo;
import com.example.mytayunapi.Entity.productsInfo;
import com.example.mytayunapi.Mapper.ProductImagesInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@Service
public class ProductImagesInfoServiceImpl implements ProductImagesInfoService {

    @Autowired
    private ProductImagesInfoMapper productImagesInfoMapper;


    @Override
    public List<ProductImagesInfo> getProductImagesById(Integer productId) {
        return productImagesInfoMapper.getProductImagesById(productId);
    }
    @Override
    public void saveProductImagesInfo(ProductImagesInfo productImagesInfo) {
        productImagesInfoMapper.insertProductImagesInfo(productImagesInfo);
    }

    @Override
    public void saveProductImages(Integer productId, List<String> imagePaths) throws IOException {
        for (String imagePath : imagePaths) {
            ProductImagesInfo productImage = new ProductImagesInfo();
            productImage.setProduct_id(productId);
            productImage.setProduct_image(imagePath);
            productImagesInfoMapper.insertProductImagesInfo(productImage);
            // Optionally save the file to disk here
        }
    }


}
